package Model;

import java.io.Serializable;

import Messaging.Notification;
import Messaging.NotificationManager;

/*
 * @author Paolo Cordova
 */

public class PlayerFree extends PlayerState implements Serializable
{

	private static PlayerFree INSTANCE = null;
	final static long serialVersionUID = 210;
	
	protected PlayerFree() 
	{
	
	}
	
	public static PlayerState Instance() 
	{
		if (INSTANCE == null) 
		{
			INSTANCE = new PlayerFree();
		}

		return INSTANCE;
	}

	@Override
	public void movePiece(Player player, int spaces) 
	{
		player.updatePosition(spaces);
	}
	
	public void movePiece(Player player, Dice dice) 
	{
		player.updatePosition(dice.getTotalRoll());
	}
	
	@Override
	public void collectRent(Player payee, int amount, Player payer) 
	{

		if (payer.getIndex() != payee.getIndex()) 
		{
			payee.updateCash(amount);
			payer.updateCash(-amount);
			NotificationManager.getInstance().notifyObservers(Notification.ACTION_MESSAGE, 
					payer.getName() + " paid $" + amount + " in rent to " + payee.getName());
		}
	}

	@Override
	public void goToJail(Player player)
{
		player.changeState(PlayerInJail.Instance());
	}
	
	@Override
	public void getOutOfJail(Player player) 
	{
	
	}
	
	public String toString() 
	{
		return "PlayerFree";
	}
}
